<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateQhCdkeysTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('qh_cdkeys', function (Blueprint $table) {
            $table->id();
            $table->integer('groupId', false, true)->index()->nullable()->comment('组ID');
            $table->integer('courseId', false, true)->nullable()->comment('可激活的学科ID，指定题库时才会记录');
            $table->integer('activeCourseId', false, true)->nullable()->comment('激活的学科ID');
            $table->integer('userId', false, true)->nullable()->comment('用户ID');
            $table->integer('orderId', false, true)->nullable()->comment('订单ID');
            $table->string('code')->index()->unique()->comment('激活码');
            $table->tinyInteger('status')->default(1)->comment('状态：1:未使用, 2:已使用, 3:已失效');
            $table->timestamp('expires')->nullable()->comment('过期时间');
            $table->timestamp('useAt')->nullable()->comment('使用时间');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('qh_cdkeys');
    }
}
